Modern microprocessors may perform numerous functions requiring a change of context state. For example, a microprocessor may change context state information when switching between groups of instructions, such as software threads. In changing between software threads, for example, context state of one group of instructions may be saved to a memory location and the context state of another group of instructions may be restored from memory and loaded into the microprocessor.
The term “context switch” typically refers to a change from one processor execution state to another, such as a software thread switch. A context switch is typically performed either by the operating system or by a user's program. For example, a context switch may occur as a result of calling a subroutine within a user's program, in which the calling program's context is saved in a storage area, such as a stack when the call to the subroutine occurs, and restored from the storage area when returning from the called subroutine. A context switch may also refer to a transition from a host mode to a virtual machine mode (a “VM entry”) or vice versa (a “VM exit”).
Consistency checks may be performed as part of the execution of instructions that effect context switches. For example, in processor in the Intel® Pentium® Processor Family, consistency checks are performed on certain control register fields such as CR0.CD, CR0.PG, CR4.PGE, etc to make sure they hold valid values for the target context to which to be transitioned. Consistency checks are especially important when the new state is being loaded from unprotected and entrusted memory structures.